
#include <ros/ros.h>
#include "customize_topic/Person.h"

int main(int argc, char *argv[])
{
    setlocale(LC_ALL, "");
    ros::init(argc, argv, "talker_person");

    ros::NodeHandle nh;

    ros::Publisher chatter_pub = nh.advertise<customize_topic::Person>("chatter_person", 100);
    //设置发送频率
    ros::Rate loop_rate(1);
    //设置次数
    customize_topic::Person msg;
    msg.name = "lixiaoming";
    msg.age = 8;
    msg.height = 1.3;

    while(ros::ok())
    {
        ROS_INFO("我叫:%s, 今年%d岁，身高：%f米", msg.name.c_str(), msg.age, msg.height);
        //发布话题
        chatter_pub.publish(msg);
        //用于处理订阅话题回调函数，虽然没有订阅消息，但是为了保证功能正常，默认加入
        ros::spinOnce();
        //调用休眠函数，保证发布频率为1HZ
        loop_rate.sleep();

        msg.age++;
        msg.height += 0.1;
    }

    return 0;
}